package com.share.design.composite;

import com.share.design.command.BakeChickenWingCommand;

import java.util.ArrayList;
import java.util.List;

/**
 * 叶子节点
 * author:caifan
 * date:2020/2/5
 */

public class Bags implements Articles {
    private String name;
    private List<Articles> articlesList = new ArrayList<>();

    public Bags(String name) {
        this.name = name;
    }

    public void add(Articles articles) {
        articlesList.add(articles);
    }

    public void remove(Articles articles) {
        articlesList.remove(articles);
    }

    @Override
    public float calculate() {
        float sum = 0f;
        for (Articles articles : articlesList) {
            sum += articles.calculate();
        }
        System.out.println("总价：" + sum);
        return sum;
    }

    @Override
    public void show() {
        for (Articles articles : articlesList) {
            articles.show();
        }
    }
}
